using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using JSON;

public class JSONBox{
	#region 单例
	private static JSONBox instance;
	public static JSONBox getInstance(){
	if (instance == null)
		instance = new JSONBox ();
		return instance;
	}
	#endregion

	#region 变量
	private JSONNode json;
	private JSONNode JSONData{
		get{
			if(json == null)
				json = JsonRead.Read("JSONBox");
			return json;
		}
	}
	#endregion
	#region 外部调用
	public void Clear(){
		json = null;
	}
	public JSONNode GetJSON(string key){
		return JSONData [key];
	}
	public JSONNode GetJSON(int index){
		return JSONData [index];
	}
	/// <summary>
	/// 有多少个数据
	/// </summary>
	public int GetCount(){
	return JSONData.Count;
	}

    /// <summary>
	/// GetJSONNodeList Like Target
	/// </summary>
	public int[] GetListID(int target){
		List<int> list = new List<int>();
		for (int i = 0; i < GetCount(); i++) {
			if( GetID(i) == target)
				list.Add(i);
		}
		return list.ToArray();
	}
	/// <summary>
	/// 物品ID
	/// </summary>
	public int GetID(string key){
		JSONNode json = GetJSON (key);
		int  value;
		value = json["ID"].AsInt;
		return  value;
	}
	/// <summary>
	/// 物品ID :From Index
	/// </summary>
	public int GetID(int index){
		int value;
		JSONNode json = GetJSON (index);
		if(json == null){
			value = GetID(index.ToString());
			return  value;
		}
		value = json["ID"].AsInt;
		return  value;
	}
    /// <summary>
	/// GetJSONNodeList Like Target
	/// </summary>
	public int[] GetListquality(int target){
		List<int> list = new List<int>();
		for (int i = 0; i < GetCount(); i++) {
			if( Getquality(i) == target)
				list.Add(i);
		}
		return list.ToArray();
	}
	/// <summary>
	/// 品质
	/// </summary>
	public int Getquality(string key){
		JSONNode json = GetJSON (key);
		int  value;
		value = json["quality"].AsInt;
		return  value;
	}
	/// <summary>
	/// 品质 :From Index
	/// </summary>
	public int Getquality(int index){
		int value;
		JSONNode json = GetJSON (index);
		if(json == null){
			value = Getquality(index.ToString());
			return  value;
		}
		value = json["quality"].AsInt;
		return  value;
	}
    /// <summary>
	/// GetJSONNodeList Like Target
	/// </summary>
	public int[] GetListopenTime(int target){
		List<int> list = new List<int>();
		for (int i = 0; i < GetCount(); i++) {
			if( GetopenTime(i) == target)
				list.Add(i);
		}
		return list.ToArray();
	}
	/// <summary>
	/// 开启时间 ((分钟)) 
	/// </summary>
	public int GetopenTime(string key){
		JSONNode json = GetJSON (key);
		int  value;
		value = json["openTime"].AsInt;
		return  value;
	}
	/// <summary>
	/// 开启时间 ((分钟))  :From Index
	/// </summary>
	public int GetopenTime(int index){
		int value;
		JSONNode json = GetJSON (index);
		if(json == null){
			value = GetopenTime(index.ToString());
			return  value;
		}
		value = json["openTime"].AsInt;
		return  value;
	}
    /// <summary>
	/// GetJSONNodeList Like Target
	/// </summary>
	public int[] GetListgold(int target){
		List<int> list = new List<int>();
		for (int i = 0; i < GetCount(); i++) {
			if( Getgold(i) == target)
				list.Add(i);
		}
		return list.ToArray();
	}
	/// <summary>
	/// 金币数量
	/// </summary>
	public int Getgold(string key){
		JSONNode json = GetJSON (key);
		int  value;
		value = json["gold"].AsInt;
		return  value;
	}
	/// <summary>
	/// 金币数量 :From Index
	/// </summary>
	public int Getgold(int index){
		int value;
		JSONNode json = GetJSON (index);
		if(json == null){
			value = Getgold(index.ToString());
			return  value;
		}
		value = json["gold"].AsInt;
		return  value;
	}
    /// <summary>
	/// GetJSONNodeList Like Target
	/// </summary>
	public int[] GetListcardType(string target){
		List<int> list = new List<int>();
		for (int i = 0; i < GetCount(); i++) {
			if( GetcardType(i) == target)
				list.Add(i);
		}
		return list.ToArray();
	}
	/// <summary>
	/// 掉落数量 ([装备，技能卡，怪物卡]) 
	/// </summary>
	public string GetcardType(string key){
		JSONNode json = GetJSON (key);
		string  value;
		value = json["cardType"].ToString();
		return  value;
	}
	/// <summary>
	/// 掉落数量 ([装备，技能卡，怪物卡])  :From Index
	/// </summary>
	public string GetcardType(int index){
		string value;
		JSONNode json = GetJSON (index);
		if(json == null){
			value = GetcardType(index.ToString());
			return  value;
		}
		value = json["cardType"].ToString();
		return  value;
	}

	#endregion
}